<?php

class RL_Meta_File extends RL_Meta
{
	public function setMimeType( $type ) {
		$this->mime_type = $type;
		return $this;
	}
	
	public function getMimeType ()
	{
		if (!isset($this->mime_type)) {
			
			if (isset($this->ctx->mime)) {
				$res = $this->ctx->mime->file($this->getObject()->getPath());
			} else {
				$res = "application/force-download";
			} 
			$this->setMimeType($res);
			
		}
		return $this->mime_type;
	} // end of function getMimeType

	public function getLastModified ()
	{
		$fpath = $this->getObject()->getPath();
		$res = filemtime( $fpath );
		return $res;
	} // end of function getLastModified

	public function getETag ()
	{
		$fpath = $this->getObject()->getPath();
		return sprintf('"%x-%x-%x"', fileinode($fpath), filesize($fpath), filemtime($fpath) );
	} // end of function getETag

	public function getLength ()
	{
		$fpath = $this->getObject()->getPath();
		return filesize($fpath);
	} // end of function getLength

	public function getFileName ()
	{
		if (!isset($this->filename)) {
			$fpath = $this->getObject()->getPath();
			$this->filename = basename($fpath);
		}
		return $this->filename;
	} // end of function getFileName

	public function setFileName ($value)
	{
		$this->filename = $value;
		return $this;
	} // end of function setFileName

}

